﻿Ext.define('app.prm.detail.Center', {
    extend: 'Ext.panel.Panel',
    region: 'center',
    split: true,
    border: true,
    layout: 'fit',
    projectId: 0,
    openCategory: null,
    initComponent: function () {
        var me = this;
        me.items = [me.getTabPanel()];
        me.callParent();
    },
    getTabPanel: function () {
        var me = this;
        if (!this.tabPanel) {
            this.tabPanel = new Ext.tab.Panel({
                border: false,
                layout: 'fit',
                tabBar: {
                    items: [
                        {
                            xtype: 'component',
                            flex: 1
                        },
                        {
                            xtype: 'button',
                            bind: {
                                hidden: '{!showEditInfo}'
                            },
                            text: '编辑基本信息',
                            handler: 'onEditInfo'
                        },
                        {
                            xtype: 'button',
                            bind: {
                                hidden: '{!showSavePhase}'
                            },
                            text: '保存阶段',
                            handler: 'onSavePhase'
                        }
                    ]
                },
                items: [
                    this.getProjectInfo(),
                    {
                        title: '项目|阶段进展',
                        tabType: 'phase',
                        scrollable: 'vertical',
                        items: [
                            {
                                layout: 'border',
                                height: 400,
                                items: [
                                     Ext.create('app.prm.detail.Phase', { projectId: me.projectId, region: 'center' }),
                                     {
                                         xtype: 'panel',
                                         border: false,
                                         split: {
                                             size: 2
                                         },
                                         region: 'east', width: 200,
                                         title: '任务进展描述',
                                         border: true,
                                         layout: 'fit',
                                         items: [
                                         Ext.create("Ext.form.field.TextArea", {
                                             border: false,
                                             reference: 'projectTaskNote', bind: { value: '{taskNote}' }
                                         })
                                         ]
                                     }

                                ]
                            }
                            ,
                            Ext.create("app.prm.detail.ProgressList", { projectId: me.projectId, title: '项目状态' })
                        ]
                    },
                    {
                        title: localize('ProjectNews'),
                        border: false,
                        layout: 'fit',
                        items: [
                            Ext.create("app.prm.detail.OperatorLog", { projectId: me.projectId })
                        ]
                    },
                     {
                         title: localize('DocNews'),
                         border: false,
                         layout: 'fit',
                         items: [
                             Ext.create("app.prm.detail.OperatorLog", { projectId: me.projectId, Operation: 20 })
                         ]
                     },
                    {
                        title: '项目任务',
                        border: false,
                        itemId: 'tab4',
                        layout: 'fit',
                        items: [
                            Ext.create("app.prm.project_task.TaskInfo", { projectId: me.projectId })
                        ]
                    }
                ],
                listeners: {
                    tabchange: 'onTabActivate'
                }
            });
        }
        return this.tabPanel;
    },
    getProjectInfo: function () {
        var me = this;
        if (!this.prmInfo) {
            this.prmInfo = new Ext.form.Panel({
                defaultType: 'displayfield',
                bodyStyle: 'padding:10px',
                border: true,
                tabType: 'basic',
                autoScroll: 'y',
                title: localize('BasicInfo'),
                items: [
                    { fieldLabel: localize('ProjectNo'), name: 'projectNo', bind: { value: '{projectNo}' } },
                    { fieldLabel: localize('ProjectName'), name: 'projectName', bind: { value: '{projectName}' } },
                    { fieldLabel: localize('PilotLocation'), hidden: true, name: 'address', bind: { value: '{address}' } },
                    { fieldLabel: localize('ProductNo'), name: 'productNo', bind: { value: '{productNo}' } },
                    { fieldLabel: '客户名称', name: 'customer', bind: { value: '{customer}' } },
                    { fieldLabel: '客户周报', bind: { value: '{customerWeek}' } },
                    { fieldLabel: '事业部', name: 'business', bind: { value: '{business}' } },
                    { fieldLabel: localize('RdCenter'), name: 'rdCenter', bind: { value: '{rdCenter}' } },
                    { fieldLabel: localize('Laboratory'), name: 'laboratory', bind: { value: '{laboratory}' } },
                    { fieldLabel: localize('CustomerCode'), name: 'customeCode', bind: { value: '{customeCode}' } },
                    { fieldLabel: localize('QualityStandard'), hidden: true, name: 'qualityStandard', bind: { value: '{qualityStandard}' } },
                    { fieldLabel: localize('ProjectNature'), hidden: true, name: 'projectNature', bind: { value: '{projectNature}' } },
                    { fieldLabel: '项目阶段', bind: { value: '{phaseText}' } },
                    { fieldLabel: localize('Remark'), name: 'remark', bind: { value: '{remark}' } }
                ]
            });
        }
        return this.prmInfo;
    },
    listeners: {
        afterrender: function (me) {
            if (me.openCategory) {
                me.getTabPanel().setActiveItem('tab4');
            }
        }
    }
})